﻿@{
    ViewData["Title"] = "Home Page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>

    <input type="text" id="txt_url" style="width:500px;height:40px;" />
    <a href="javascript:void(0);" onclick="geturl()">获取url</a><br />
    <span id="url"></span>
</div>

<script>

    function geturl() {

        var reg = /(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@@?^=%&:/~\+#]*[\w\-\@@?^=%&/~\+#])/g;
        var content = document.getElementById("txt_url").value;
        //var res = content.match(reg);
        //console.log(res)

        //while (reg.exec(content)) {
        //    console.log(RegExp.$1)
        //}
        console.log(content);
        var regexp = /(ftp:\/\/|http:\/\/|https:\/\/)((\w|=|\?|\.|\/|\&|-)+)/g;
        var newcontent = content.replace(reg, function ($url) {
            return "<a href='" + $url + "' target='_blank'>" + $url + "</a>";
        });
        console.log(newcontent);
        document.getElementById("url").innerHTML = newcontent;
    }

    function geturl1(content) {

        console.log(content);
        var reg = /(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@@?^=%&:/~\+#]*[\w\-\@@?^=%&/~\+#])/g;
        var regexp = /(ftp:\/\/|http:\/\/|https:\/\/)((\w|=|\?|\.|\/|\&|-)+)/g;

        var newcontent = content.replace(reg, function ($url) {
            return "<a href='" + $url + "' target='_blank'>" + $url + "</a>";
        });

        console.log(newcontent);
        return newcontent;
    }

</script>